package tech.aistar.design.singleton;

import java.io.*;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2022/7/22 4:13 下午
 */
public class IODemo {
    public static void main(String[] args) {
       Singleton04 s = Singleton04.getInstance();

       try(ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("src/tech/aistar/design/singleton/xx.txt"))){
           out.writeObject(s);
       } catch (IOException e) {
           e.printStackTrace();
       }

        Singleton04 s1 = read();
        Singleton04 s2 = read();
        System.out.println(s1 == s2);//false
    }

    public static Singleton04 read(){
        try(ObjectInputStream in = new ObjectInputStream(new FileInputStream("src/tech/aistar/design/singleton/xx.txt"))){
            Singleton04 s2 = (Singleton04) in.readObject();
            return s2;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }
}
